import java.io.FileNotFoundException;
import java.util.*;


public class ManagerDeployee {
    private final String PATH = "D:\\KTU.txt";
    private final String PATH1 = "D:\\KTU_sal.txt";

    public String getPATH1() {
        return PATH1;
    }

    List<Deployee> deployeeList = new LinkedList<Deployee>();

    public String getPATH() {
        return PATH;
    }

    public boolean addDeployee(String name, double ktu, String local) {
        deployeeList.add(new Deployee(ktu, name, local));
        boolean b = addFile();
        return b;
    }

    public boolean addFile() {
        try {
            List<String> ld = new LinkedList<String>();
            Iterator<Deployee> it = deployeeList.iterator();
            while (it.hasNext()) {
                ld.add(it.next().toString());
            }
            FileMaster.writeToFile(ld, getPATH());
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public boolean delDeploy(String name) {
        try {
            List<String> ld = new ArrayList<String>();
            ld = FileMaster.getFileContent(PATH);
            Iterator<String> it = ld.iterator();
            while (it.hasNext()) {
                String tmp = it.next();
                if (tmp.contains(name) && !equals(" ")) {
                    it.remove();
                }

            }
            FileMaster.writeToFile(ld, getPATH());

            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public List<Deployee> generList(){
        List<Deployee> dList = new ArrayList<Deployee>();
        List<String> list = FileMaster.getFileContent(getPATH());
        Iterator<String> it = list.iterator();

        while (it.hasNext()){
dList.add(new Deployee(it.next()));
        }     return dList;
    }

}
